/*
2021-7-31
https://www.acwing.com/problem/content/3790/
*/
#include<iostream>

using namespace std;

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int a,b;
        cin>>a>>b;
        if(a%b == 0) cout<<0<<endl;
        else cout<<b-(a%b)<<endl;
    }
    return 0;
}
